package top.zhangjianyong.blog.portal.controller;

import java.util.concurrent.ExecutionException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.zhangjianyong.blog.params.blog.BlogGetParam;
import top.zhangjianyong.blog.params.blog.BlogPageParam;
import top.zhangjianyong.blog.params.blog.BlogTopListParam;
import top.zhangjianyong.blog.response.ApiResponse;
import top.zhangjianyong.blog.service.BlogService;

/**
 * 博客前台展示接口
 *
 * @author zhangjianyong
 * @since 2024/8/11 下午3:26
 */
@RequestMapping("/portal/blog")
@RestController("portalBlogController")
public class BlogController {

  private final BlogService blogService;

  public BlogController(BlogService blogService) {
    this.blogService = blogService;
  }

  @PostMapping("/page")
  public ApiResponse page(@RequestBody @Validated BlogPageParam param)
      throws ExecutionException, InterruptedException {
    return blogService.portalPage(param);
  }

  // 查询置顶的博客
  @PostMapping("/top/list")
  public ApiResponse topList(@RequestBody @Validated BlogTopListParam param)
      throws ExecutionException, InterruptedException {
    return blogService.topList(param);
  }

  @PostMapping("/get")
  public ApiResponse get(@RequestBody @Validated BlogGetParam param) {
    return blogService.get(param);
  }
}
